Gradient Descent Methods
This tour explores the use of gradient descent method for unconstrained and constrained optimization of a smooth function
Contents
Installing toolboxes and setting up the path.
You need to download the following files: signal toolbox and general toolbox.
You need to unzip these toolboxes in your working directory, so that you have toolbox_signal and toolbox_general in your directory.
For Scilab user: you must replace the Matlab comment '%' by its Scilab counterpart '//'.
Recommandation: You should create a text file named for instance numericaltour.sce (in Scilab) or numericaltour.m (in Matlab) to write all the Scilab/Matlab command you want to execute. Then, simply run exec('numericaltour.sce'); (in Scilab) or numericaltour; (in Matlab) to run the commands.
Execute this line only if you are using Matlab.
getd = @(p)path(p,path); % scilab users must *not* execute this
Then you can add the toolboxes to the path.
getd('toolbox_signal/'); getd('toolbox_general/');
Gradient Descent for Unconstrained Problems
We consider the problem of finding a minimum of a function
Note that the minimum is not necessarily unique. In the general case,
The simplest method is the gradient descent, that computes
In the convex case, if
Gradient Descent in 2-D
We consider a simple problem, corresponding to the minimization of a 2-D quadratic form
Anisotropy parameter
eta = 10;
Function
f = @(x)( x(1)^2 + eta*x(2)^2 ) /2;
Background image of the function.
t = linspace(-.7,.7,101); [u,v] = meshgrid(t,t); F = ( u.^2 + eta*v.^2 )/2 ;
Display the function as a 2-D image.
clf; hold on; imagesc(t,t,F); colormap jet(256); contour(t,t,F, 20, 'k'); axis off; axis equal;
Gradient.
Gradf = @(x)[x(1); eta*x(2)];
The step size should satisfy
tau = 1.8/eta;
Exercice 1: (the solution is exo1.m) Perform the gradient descent using a fixed step size
exo1;
Display the iterations.
clf; hold on; imagesc(t,t,F); colormap jet(256); contour(t,t,F, 20, 'k'); h = plot(X(1,:), X(2,:), 'k.-'); set(h, 'LineWidth', 2); set(h, 'MarkerSize', 15); axis off; axis equal;
Exercice 2: (the solution is exo2.m) Display the iteration for several different step sizes.
exo2;
Gradient Descent in Image Processing
We consider now the problem of denoising an image
Load a clean image.
n = 256;
name = 'lena';
x0 = rescale( load_image(name, n) );
Display it.
clf; imageplot(x0);
Add noise to it, to simulate a noisy image.
sigma = .1; y = x0 + randn(n)*sigma;
Display the noisy image
clf; imageplot(clamp(y));
Denoising is obtained by minimizing the following functional
The gradient of the functional read
Value for
lambda = .3;
Value for
epsilon = 1e-3;
TV norm.
Amplitude = @(u)sqrt(epsilon^2 + sum(u.^2,3)); J = @(x)sum(sum(Amplitude(Grad(x))));
Function to minimize.
f = @(x)1/2*norm(x-y,'fro')^2 + lambda*J(x);
Gradient of TV norm. Note that div implement
Normalize = @(u)u./repmat(Amplitude(u), [1 1 2]); GradJ = @(x)-div( Normalize(grad(x)) );
Gradient of the functional.
Gradf = @(x)x-y+lambda*GradJ(x);
The step size should satisfy
tau = 1.8/( 1 + lambda*8/epsilon ); tau = tau*4;
Exercice 3: (the solution is exo3.m) Implement the gradient descent. Monitor the decay of
exo3;
Display the resulting denoised image.
clf; imageplot(x);